package com.ke.searchhouse.base;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author  keke
 * @create  2018/10/9 0009 下午 8:32
 * @desc 统一响应
 **/
@Data
public class Response {
     private Integer code;
     private String message;
     private Object data;
     private boolean isMore;

     public Response() {
         this.code = Status.SUCCESS.getCode();
         this.message = Status.SUCCESS.getStandardMessage();
     }

     public static Response ofMessage(int code, String message) {
         return new Response(code, message, null);
     }

    public static Response ofSuccess(Object data) {
        return new Response(Status.SUCCESS.getCode(), Status.SUCCESS.getStandardMessage(), data);
    }

    public static Response ofStatus(Status status) {
        return new Response(Status.SUCCESS.getCode(), Status.SUCCESS.getStandardMessage(), null);
    }
     
     public Response(int code, String message, Object data) {
         this.code = code;
         this.message = message;
         this.data = data;
     }



     public enum Status {
         SUCCESS(200, "OK"),
         BAD_REQUEST(400, "Bad Request"),
         INTERNAL_SERVER_ERROR(500, "Unknown Internal Error"),
         NOT_VALID_PARAM(40005, "Not Valid Params"),
         NOT_SUPPORTED_OTERATION(40006, "Operation Not Support"),
         NO_LOGIN(50000, "No Login"),
         NOT_FOUND(404, "No Found");

         private int code;
         private String standardMessage;

         Status(int code, String standardMessage) {
             this.code = code;
             this.standardMessage = standardMessage;
         }

         public int getCode() {
             return code;
         }

         public void setCode(int code) {
             this.code = code;
         }

         public String getStandardMessage() {
             return standardMessage;
         }

         public void setStandardMessage(String standardMessage) {
             this.standardMessage = standardMessage;
         }
     }




}
